package com.cyh.core.framework.common.constant;

import java.time.LocalDate;

import com.cyh.core.framework.common.utils.TimeUtil;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: yanhang_chen
 * @Date: 2020-09-15 15:47:43
 */
@Component
public  class TimeConstant {

    public static final long SECOND = 1000L;

    public static final long MINUTE = 60 * SECOND;

    public static final long HOUR = 60 * MINUTE;

    public static final long DAY = 24 * HOUR;

    public volatile static long MONTH = DAY * LocalDate.now().lengthOfMonth();

    public volatile static long YEAR = DAY * LocalDate.now().lengthOfYear();

    //项目启动后等待 initialDelay 再执行，每次执行完等待fixedDelay
    @Scheduled( initialDelay = 10*SECOND , fixedDelay = 1*DAY )
    private synchronized static void update(){
        MONTH = DAY * LocalDate.now().lengthOfMonth();
        YEAR = DAY * LocalDate.now().lengthOfYear();
        System.out.println(TimeUtil.getNow() +" Update MONTH and YEAR");
    }

}
